﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

/*
Developed By: Bhupender Bindra
Developed On: 16th Jan 2010
Description: The code provides the user to get admin status.   
*/

namespace SiteProjects.Classes
{
    public class SiteProjectsUtility
    {
        SqlConnection connection;
        SqlCommand command;

        /// <summary>
        /// count the site admin url with current user
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="siteUrl"></param>
        /// <returns></returns>
        public int GetSiteAdminStatus(string currentUser, string siteUrl)
        {
            int countProject;
            //connection fetch by web.config file and stored procedure call
            connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ASPNET_WSS_Content"].ConnectionString);
            command = new SqlCommand("proc_GetSiteAdmin", connection); // Calling Stored procedure //
            command.Parameters.AddWithValue("@UserName", currentUser.ToString()); //passing Parameter to StoredProcedure //
            command.Parameters.AddWithValue("@URL", siteUrl.ToString());
            SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int);
            paramStatus.Direction = ParameterDirection.Output;
            command.Parameters.Add(paramStatus);
            command.CommandType = CommandType.StoredProcedure;
            connection.Open(); // connection open
            command.ExecuteNonQuery();
            connection.Close(); // connection close
            countProject = Convert.ToInt32(paramStatus.Value.ToString()); //get the status
            return countProject;
        }

        /// <summary>
        /// count the site admin url with current user
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="siteUrl"></param>
        /// <returns></returns>
        public int GetSiteOwnerStatus(string currentUser, string siteUrl)
        {
            int countProject;
            //connection fetch by web.config file and stored procedure call
            connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ASPNET_WSS_Content"].ConnectionString);
            command = new SqlCommand("proc_CheckSiteOwner", connection); // Calling Stored procedure //
            command.Parameters.AddWithValue("@UserName", currentUser.ToString()); //passing Parameter to StoredProcedure //
            command.Parameters.AddWithValue("@URL", siteUrl.ToString());
            SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int);
            paramStatus.Direction = ParameterDirection.Output;
            command.Parameters.Add(paramStatus);
            command.CommandType = CommandType.StoredProcedure;
            connection.Open(); // connection open
            command.ExecuteNonQuery();
            connection.Close(); // connection close
            countProject = Convert.ToInt32(paramStatus.Value.ToString()); //get the status
            return countProject;
        }
    }
}
